
#include "init.h"
#include "../teximage/teximage.h"

#include "m_menu.h"

////////////////////////////////////////////////////////////////////////////////
struct options_menu : Menu
{
    options_menu()
    {
        add_textbox( "ip|server address", ip, Menu::accept_ip );

        add_space(32);

        add_textbox( "nam|player name", name, Menu::accept_nick );
        add_entry( "col|colors" );

        add_space(32);

        add_checkbox( "fullscreen", &fullscreen );
        add_checkbox( "half draw rate", &halfdrawrate );

        add_space(32);

        add_entry( "ok" );
        add_entry( "cancel" );
        set_escape_code( "cancel" );
    }

    charstr ip;
    charstr name;
    int fullscreen;
    int halfdrawrate;
};

////////////////////////////////////////////////////////////////////////////////
void bman_net::draw_options( int key )
{
    static int binit=0;
    static options_menu menu;

    if(key) {
        token k = menu.onkeypress(key);
        if( k == "col" )
        {
            CW.gs.state = C_World::GSC_CFGCOLOR;
        }
        else if( k == "ok" )
        {
            CW._profile._ip = menu.ip;
            CW._profile._nick = menu.name;
            CW._profile._fullscreen = menu.fullscreen != 0;
            CW._profile._drawratehalf = menu.halfdrawrate != 0;

            CW.save_profile();
            CW.gs.state = C_World::GSC_INITIAL;
            binit = false;
        }
        else if ( k == "cancel" )
        {
            CW.gs.state = C_World::GSC_INITIAL;
            binit = false;
        }
        return;
    }

    if(!binit)
    {
        menu.ip = CW._profile._ip;
        menu.name = CW._profile._nick;
        menu.fullscreen = CW._profile._fullscreen;
        menu.halfdrawrate = CW._profile._drawratehalf;
        binit = true;
    }

    SCREEN.clear(0x3f3f3f);
    menu.draw();
}

